<?php
session_start();

if (!$_SESSION['loggedin']) {
    // User not logged in, redirect to login page
    echo "<script language='javascript'>window.location='index.php'</script>";
}
if ($_SESSION['loggedin'] && $_SESSION['accounttype'] == 'registrar') {
?>
    <html>    
        <head>
            <link rel="stylesheet" href="css/style.css" type="text/css" id="" media="print, projection, screen" />
            <script type="text/javascript" src="script/jquery-latest.js"></script>
            <script type="text/javascript" src="script/jquery.validate.js"></script>
            <script type="text/javascript">
                $(document).ready(function(){
                    $("#commentForm").validate({
                        rules: {
                            password: "required",
                            password_again: {
                                equalTo: "#password"
                            }
                        }
                    });
                });

                function confirmUpdate()
                {
                    var agree=confirm("Are you sure you want to update?");
                    if (agree)
                        return true ;
                    else
                        return false ;
                }
                function confirmLogout()
                {
                    var agree=confirm("Are you sure you want to Logout?");
                    if (agree)
                        return true ;
                    else
                        return false ;
                }

            </script>

            <title>TUP Student Management</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>

        <body style=" height:100%; width: 100%; background-image: url(image/wall6.jpg);">

            <div id="container" style="height:auto; width: 100%;">

                <div style="background-image: url(image/wall12.jpg); height: 110px; width: auto; ">
                </div>

                <div align="center" style="background-image: url(image/wall11.jpg);  height: 74px; width: auto;">

                    <div align="center" style=" height: 4px; width: auto;"></div>
                    <div align="center" style=" height: 22px; width: auto;">
                        <a href="TMMViewProf.php"><b>Professor Management</b></a>&nbsp;&nbsp;
                        <a href="SMMViewStud.php"><b>[ Student Management ]</b></a>&nbsp;&nbsp;
                        <a href="CMMViewCourse.php"><b>Course Management</b></a>&nbsp;&nbsp;
                        <a href="EMSelectProf.php"><b>Enrollment</b></a>
                    </div>
                    <div align="center" style=" height: 4px; width: auto;"></div>
                    <div align="center" style=" height: 22px; width: auto;">
                        <a href="SMMAddStud.php" >Add Student</a>&nbsp;
                        <a href="SMMViewStud.php">View Student</a>&nbsp;
                        <a href="SMMSearchStud.php">Search Student</a>&nbsp;
                    </div>

                    <div  align="left" style="padding-left: 4%; height: 18px; width: 46%;float:left;"><?php echo "<aa class=\"smallw\"><b>Welcome " . $_SESSION['fname'] . ", Last login: " . $_SESSION['lastlogin'] . "</b></aa>"; ?>
                    </div>
                    <div align="right" style="padding-right: 4%; height: 18px; width: 46%;float:left;"><bb>|</bb>
                        <a class="small" href="RegEditProfile.php"><b>Edit Profile</b></a>
                        <bb>|</bb>
                        <a onclick="return confirmLogout()" class="small" href="Logout.php"><b>Logout</b></a>
                        <bb>|</bb></div>
                </div>

                <div align="left" style="padding-left: 4%;  float:left; width: 96%;">


                    <h2>Edit Student</h2>

                <?php
                //10546456
                $studidno = $_POST['stude'];

                if (isset($_POST['update'])) {
                    $fname = $_POST['fname'];
                    $mname = $_POST['mname'];
                    $lname = $_POST['lname'];
                    $address = $_POST['address'];
                    $email = $_POST['email'];
                    $celno = $_POST['celno'];
                    $mm = $_POST['mm'];
                    $dd = $_POST['dd'];
                    $yyyy = $_POST['yyyy'];
                    $dash = '-';
                    $birthdate = $yyyy . $dash . $mm . $dash . $dd;

                    include 'DBLibrary/config.php';
                    include 'DBLibrary/openDB.php';

                    mysql_select_db($dbname);

                    $updatequery = "update student set fname='" . $fname . "', mname='" . $mname . "', lname='" . $lname . "', address='" . $address . "', birthdate='" . $birthdate . "', celno='" . $celno . "', email='" . $email . "' where studidno='" . $studidno . "'";
//  $query4 ="update user set birthdate='".$birthdate . "', fname='" .$fname ."', lname='". $lname."', mname='" .$mname . "', gender='". $gender . "', email='".$email."', password='".$password."', address='".$address."', telnumber='". $telnumber."', mobnumber='".$mobnumber . "' where username='".$_SESSION['username']."'";

                    $queryvalue = mysql_query($updatequery);

                    if ($queryvalue == 0) {
                        echo "<a class=\"red\">" . mysql_errno($conn) . ": " . mysql_error($conn) . "</a>\n";
                        echo "<h3 class=\"err\">Update failed</h3>";
                    } else if ($queryvalue == 1)
                        echo "<h3 class=\"err\">Student has been updated</h3>";


                    include 'DBLibrary/closeDB.php';
                }


                include 'DBLibrary/config.php';
                include 'DBLibrary/openDB.php';

                mysql_select_db($dbname);
                $queryselectedstud = "select studidno, fname, mname, gender, lname, telno, year(birthdate) as yyyy, month(birthdate) as mm, day(birthdate) as dd, celno, address, email from student where studidno=\"" . $studidno . "\"";
                $selectedstud = mysql_query($queryselectedstud);
                $rowedit = mysql_fetch_array($selectedstud);
                ?>

                <h3>Student Information</h3>
                <form onsubmit="return confirmUpdate()" class="cmxform" id="commentForm" method="post" action="SMMEditStud.php">
                    <p>Student ID Number: <?php echo "<aa>" . $rowedit['studidno'] . "</aa>"; ?><br>
                        <br>First Name MI. Last Name:&nbsp;<input id="fname" type="text" name="fname" value="<?php echo $rowedit['fname']; ?>" size="14" maxlength="32" class="required" minlength="1"/>&nbsp;&nbsp;<input id="mname" type="text" name="mname" value="<?php echo $rowedit['mname']; ?>" size="1" maxlength="1" class="required" minlength="1"/>.&nbsp;&nbsp;<input id="lname" type="text" name="lname" value="<?php echo $rowedit['lname']; ?>" size="10" maxlength="32" class="required" minlength="1"/><br>
                        <input type="text" name="stude" size="1" value="<?php echo $rowedit['studidno']; ?>" style="visibility:hidden;"/>
                        <br>Gender: <?php echo "<aa>" . $rowedit['gender'] . "</aa>"; ?>  <br>
                        <br>Telephone Number: <?php echo "<aa>" . $rowedit['telno'] . "</aa>"; ?>  <br>
                        <br>
                        <label for="btm">Birth Date:</label>
                        <select id="btm" class="required" name="mm" style="margin-left: 4px;" tabindex="8">
                            <option value="">- Select Month -</option>
                            <option value="1" <?php
                if ($rowedit['mm'] == "1") {
                    echo "SELECTED";
                }
                ?> >January</option>
                            <option value="2" <?php
                                    if ($rowedit['mm'] == "2") {
                                        echo "SELECTED";
                                    } ?> >February</option>
                            <option value="3" <?php
                                    if ($rowedit['mm'] == "3") {
                                        echo "SELECTED";
                                    }
                ?> >March</option>
                            <option value="4" <?php
                                    if ($rowedit['mm'] == "4") {
                                        echo "SELECTED";
                                    } ?> >April</option>
                            <option value="5" <?php
                                    if ($rowedit['mm'] == "5") {
                                        echo "SELECTED";
                                    }
                ?> >May</option>
                            <option value="6" <?php
                                    if ($rowedit['mm'] == "6") {
                                        echo "SELECTED";
                                    } ?> >June</option>
                            <option value="7" <?php
                                    if ($rowedit['mm'] == "7") {
                                        echo "SELECTED";
                                    }
                ?> >July</option>
                            <option value="8" <?php
                                    if ($rowedit['mm'] == "8") {
                                        echo "SELECTED";
                                    } ?> >August</option>
                            <option value="9" <?php
                                    if ($rowedit['mm'] == "9") {
                                        echo "SELECTED";
                                    }
                ?> >September</option>
                            <option value="10" <?php
                                    if ($rowedit['mm'] == "10") {
                                        echo "SELECTED";
                                    } ?> >October</option>
                            <option value="11" <?php
                                    if ($rowedit['mm'] == "11") {
                                        echo "SELECTED";
                                    } ?> >November</option>
                            <option value="12" <?php
                                    if ($rowedit['mm'] == "12") {
                                        echo "SELECTED";
                                    }
                ?> >December</option>
                        </select>

                        <select id="btd" class="required" name="dd" style="margin-left: 4px;" tabindex="8">
                            <option value="">- Select Day -</option>
                            <option value="1" <?php
                                    if ($rowedit['dd'] == "1") {
                                        echo "SELECTED";
                                    }
                ?> >1</option>
                            <option value="2" <?php
                                    if ($rowedit['dd'] == "2") {
                                        echo "SELECTED";
                                    } ?> >2</option>
                            <option value="3" <?php
                                    if ($rowedit['dd'] == "3") {
                                        echo "SELECTED";
                                    }
                ?> >3</option>
                            <option value="4" <?php
                                    if ($rowedit['dd'] == "4") {
                                        echo "SELECTED";
                                    } ?> >4</option>
                            <option value="5" <?php
                                    if ($rowedit['dd'] == "5") {
                                        echo "SELECTED";
                                    }
                ?> >5</option>
                            <option value="6" <?php
                                    if ($rowedit['dd'] == "6") {
                                        echo "SELECTED";
                                    } ?> >6</option>
                            <option value="7" <?php
                                    if ($rowedit['dd'] == "7") {
                                        echo "SELECTED";
                                    }
                ?> >7</option>
                            <option value="8" <?php
                                    if ($rowedit['dd'] == "8") {
                                        echo "SELECTED";
                                    } ?> >8</option>
                            <option value="9" <?php
                                    if ($rowedit['dd'] == "9") {
                                        echo "SELECTED";
                                    }
                ?> >9</option>
                            <option value="10" <?php
                                    if ($rowedit['dd'] == "10") {
                                        echo "SELECTED";
                                    } ?> >10</option>
                            <option value="11" <?php
                                    if ($rowedit['dd'] == "11") {
                                        echo "SELECTED";
                                    }
                ?> >11</option>
                            <option value="12" <?php
                                    if ($rowedit['dd'] == "12") {
                                        echo "SELECTED";
                                    } ?> >12</option>
                            <option value="13" <?php
                                    if ($rowedit['dd'] == "13") {
                                        echo "SELECTED";
                                    }
                ?> >13</option>
                            <option value="14" <?php
                                    if ($rowedit['dd'] == "14") {
                                        echo "SELECTED";
                                    } ?> >14</option>
                            <option value="15" <?php
                                    if ($rowedit['dd'] == "15") {
                                        echo "SELECTED";
                                    }
                ?> >15</option>
                            <option value="16" <?php
                                    if ($rowedit['dd'] == "16") {
                                        echo "SELECTED";
                                    } ?> >16</option>
                            <option value="17" <?php
                                    if ($rowedit['dd'] == "17") {
                                        echo "SELECTED";
                                    }
                ?> >17</option>
                            <option value="18" <?php
                                    if ($rowedit['dd'] == "18") {
                                        echo "SELECTED";
                                    } ?> >18</option>
                            <option value="19" <?php
                                    if ($rowedit['dd'] == "19") {
                                        echo "SELECTED";
                                    } ?> >19</option>
                            <option value="20" <?php
                                    if ($rowedit['dd'] == "20") {
                                        echo "SELECTED";
                                    }
                ?> >20</option>
                            <option value="21" <?php
                                    if ($rowedit['dd'] == "21") {
                                        echo "SELECTED";
                                    } ?> >21</option>
                            <option value="22" <?php
                                    if ($rowedit['dd'] == "22") {
                                        echo "SELECTED";
                                    }
                ?> >22</option>
                            <option value="23" <?php
                                    if ($rowedit['dd'] == "23") {
                                        echo "SELECTED";
                                    } ?> >23</option>
                            <option value="24" <?php
                                    if ($rowedit['dd'] == "24") {
                                        echo "SELECTED";
                                    }
                ?> >24</option>
                            <option value="25" <?php
                                    if ($rowedit['dd'] == "25") {
                                        echo "SELECTED";
                                    } ?> >25</option>
                            <option value="26" <?php
                                    if ($rowedit['dd'] == "26") {
                                        echo "SELECTED";
                                    }
                ?> >26</option>
                            <option value="27" <?php
                                    if ($rowedit['dd'] == "27") {
                                        echo "SELECTED";
                                    } ?> >27</option>
                            <option value="28" <?php
                                    if ($rowedit['dd'] == "28") {
                                        echo "SELECTED";
                                    }
                ?> >28</option>
                            <option value="29" <?php
                                    if ($rowedit['dd'] == "29") {
                                        echo "SELECTED";
                                    } ?> >29</option>
                            <option value="30" <?php
                                    if ($rowedit['dd'] == "30") {
                                        echo "SELECTED";
                                    }
                ?> >30</option>
                            <option value="31" <?php
                                    if ($rowedit['dd'] == "31") {
                                        echo "SELECTED";
                                    } ?> >31</option>
                        </select>

                        <select id="bty" class="required" name="yyyy" style="margin-left: 4px;" tabindex="8">
                            <option value="">- Select Year -</option>
                            <option value="2011" <?php
                                    if ($rowedit['yyyy'] == "2011") {
                                        echo "SELECTED";
                                    }
                ?> >2011</option>
                            <option value="2010" <?php
                                    if ($rowedit['yyyy'] == "2010") {
                                        echo "SELECTED";
                                    }
                ?> >2010</option>
                            <option value="2009" <?php
                                    if ($rowedit['yyyy'] == "2009") {
                                        echo "SELECTED";
                                    }
                ?> >2009</option>
                            <option value="2008" <?php
                                    if ($rowedit['yyyy'] == "2008") {
                                        echo "SELECTED";
                                    }
                ?> >2008</option>
                            <option value="2007" <?php
                                    if ($rowedit['yyyy'] == "2007") {
                                        echo "SELECTED";
                                    } ?> >2007</option>
                            <option value="2006" <?php
                                    if ($rowedit['yyyy'] == "2006") {
                                        echo "SELECTED";
                                    }
                ?> >2006</option>
                            <option value="2005" <?php
                                    if ($rowedit['yyyy'] == "2005") {
                                        echo "SELECTED";
                                    }
                ?> >2005</option>
                            <option value="2004" <?php
                                    if ($rowedit['yyyy'] == "2004") {
                                        echo "SELECTED";
                                    }
                ?> >2004</option>
                            <option value="2003" <?php
                                    if ($rowedit['yyyy'] == "2003") {
                                        echo "SELECTED";
                                    }
                ?> >2003</option>
                            <option value="2002" <?php
                                    if ($rowedit['yyyy'] == "2002") {
                                        echo "SELECTED";
                                    }
                ?> >2002</option>
                            <option value="2001" <?php
                                    if ($rowedit['yyyy'] == "2001") {
                                        echo "SELECTED";
                                    }
                ?> >2001</option>
                            <option value="2000" <?php
                                    if ($rowedit['yyyy'] == "2000") {
                                        echo "SELECTED";
                                    }
                ?> >2000</option>
                            <option value="1999" <?php
                                    if ($rowedit['yyyy'] == "1999") {
                                        echo "SELECTED";
                                    }
                ?> >1999</option>
                            <option value="1998" <?php
                                    if ($rowedit['yyyy'] == "1998") {
                                        echo "SELECTED";
                                    }
                ?> >1998</option>
                            <option value="1997" <?php
                                    if ($rowedit['yyyy'] == "1997") {
                                        echo "SELECTED";
                                    }
                ?> >1997</option>
                            <option value="1996" <?php
                                    if ($rowedit['yyyy'] == "1996") {
                                        echo "SELECTED";
                                    }
                ?> >1996</option>
                            <option value="1995" <?php
                                    if ($rowedit['yyyy'] == "1995") {
                                        echo "SELECTED";
                                    }
                ?> >1995</option>
                            <option value="1994" <?php
                                    if ($rowedit['yyyy'] == "1994") {
                                        echo "SELECTED";
                                    }
                ?> >1994</option>
                            <option value="1993" <?php
                                    if ($rowedit['yyyy'] == "1993") {
                                        echo "SELECTED";
                                    }
                ?> >1993</option>
                            <option value="1992" <?php
                                    if ($rowedit['yyyy'] == "1992") {
                                        echo "SELECTED";
                                    }
                ?> >1992</option>
                            <option value="1991" <?php
                                    if ($rowedit['yyyy'] == "1991") {
                                        echo "SELECTED";
                                    }
                ?> >1991</option>
                            <option value="1990" <?php
                                    if ($rowedit['yyyy'] == "1990") {
                                        echo "SELECTED";
                                    }
                ?> >1990</option>
                        </select><br>

                        <br>Cell phone Number:&nbsp;0&nbsp;<input id="celno" type="text" name="celno" value="<?php echo $rowedit['celno']; ?>" size="10" maxlength="10" class="required digits" minlength="10"/><br>
                        <br>Address:&nbsp;<input id="address" type="text" name="address" value="<?php echo $rowedit['address']; ?>" size="50" maxlength="50" class="required" minlength="1"/><br>
                        <br>Email Address:&nbsp;<input id="email" type="text" name="email" value="<?php echo $rowedit['email']; ?>" size="32" maxlength="64" class="required email" minlength="1"/><br>
                        <br><br><input name="update" class="submit" type="submit" value="Update"/>
                    </p></form>
            </div>
        </div>

        <div id="footer" style="background-image: url(image/wall11.jpg);clear:both;text-align:center; height: 26px; width:auto;">
            <div align="center" style=" height: 4px; width: auto;"></div>
            <bb class ="small">Copyright &#169; 2011</bb>
        </div>

    </body>
</html>
<?php
                                } else if ($_SESSION['loggedin'] && $_SESSION['accounttype'] == 'admin') {
                                    echo "<script language='javascript'>window.location='UMMViewUser.php'</script>";
                                } else if ($_SESSION['loggedin'] && $_SESSION['accounttype'] == 'professor') {
                                    echo "<script language='javascript'>window.location='AMMSelectSection.php'</script>";
                                }
?>